<template>
  <el-card class="content">
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="数据预警" name="first">
        <div class="top">
          <el-form inline ref="searchForm" :model="searchForm">
            <el-form-item label="监测设备类型" prop="sensorList">
              <el-select v-model="searchForm.sensorList" size="mini" clearable>
                <el-option
                  v-for="item in options"
                  :key="item.monitorTypeId"
                  :label="item.monitorTypeName"
                  :value="item.monitorTypeId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="mini" @click="search()"
                >查询</el-button
              >
            </el-form-item>
          </el-form>
        </div>
        <el-table
          stripe
          style="width: 100%"
          :data="list"
          :header-cell-style="{ textAlign: 'center' }"
          :cell-style="{ textAlign: 'center' }"
        >
          <el-table-column prop="monitorName" label="测点名称">
          </el-table-column>
          <el-table-column prop="typeName" label="测点类型"> </el-table-column>
          <el-table-column prop="description" label="预警原因">
          </el-table-column>
          <el-table-column prop="warnType" label="预警类型">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.warnType == 1"
                type="warning"
                size="mini"
                >设备掉线</el-button
              >
              <el-button
                v-else-if="scope.row.warnType == 2"
                type="danger"
                size="mini"
                >累计预警</el-button
              >
              <el-button
                v-else-if="scope.row.warnType == 3"
                type="danger"
                size="mini"
                >相对预警</el-button
              >
            </template>
          </el-table-column>
          <!-- <el-table-column prop="dealType" label="处理方式">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.dealType === 0"
                type="success"
                size="mini"
                >正常</el-button
              >
              <el-button
                v-if="scope.row.dealType === 1"
                type="warning"
                size="mini"
                >设备掉线</el-button
              >
              <el-button
                v-if="scope.row.dealType === 2"
                type="danger"
                size="mini"
                >累计预警</el-button
              >
              <el-button
                v-if="scope.row.dealType === 3"
                type="danger"
                size="mini"
                >相对预警</el-button
              >
            </template>
          </el-table-column>
          <el-table-column prop="realName" label="处理人"> </el-table-column>
          <el-table-column prop="dealTime" label="处理时间"> </el-table-column>
          <el-table-column prop="remark" label="处理备注"> </el-table-column> -->
          <el-table-column prop="warnLevel" label="预警等级">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.warnLevel === 1"
                type="danger"
                size="mini"
                >红色预警</el-button
              >
              <el-button
                v-else-if="scope.row.warnLevel === 2"
                type="warning"
                size="mini"
                >橙色预警</el-button
              >
              <el-button
                v-else-if="scope.row.warnLevel === 3"
                size="mini"
                class="button-yellow"
                >黄色预警</el-button
              >
              <el-button
                v-else-if="scope.row.warnLevel === 4"
                type="primary"
                size="mini"
                >蓝色预警</el-button
              >
            </template>
          </el-table-column>
          <el-table-column prop="theDate" label="预警时间">
          </el-table-column>
        </el-table>
        <el-row type="flex" justify="end">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="query.page"
            :page-sizes="[10, 15]"
            :page-size="query.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </el-row>
      </el-tab-pane>
      <el-tab-pane label="设备预警" name="second">
        <div class="top">
          <el-form
            inline
            :rules="ruless"
            ref="searchForms"
            :model="searchForms"
          >
            <el-form-item label="监测设备类型" prop="sensorLists">
              <el-select v-model="searchForms.sensorLists" size="mini" clearable>
                <el-option
                  v-for="item in options"
                  :key="item.monitorTypeId"
                  :label="item.monitorTypeName"
                  :value="item.monitorTypeId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="mini" @click="searchs()"
                >查询</el-button
              >
            </el-form-item>
          </el-form>
        </div>
        <el-table
          stripe
          style="width: 100%"
          :data="lists"
          :header-cell-style="{ textAlign: 'center' }"
          :cell-style="{ textAlign: 'center' }"
        >
          <el-table-column prop="monitorName" label="测点名称">
          </el-table-column>
          <el-table-column prop="typeName" label="测点类型"> </el-table-column>
          <el-table-column prop="description" label="预警原因">
          </el-table-column>
          <el-table-column prop="warnType" label="预警类型">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.warnType === 1"
                type="warning"
                size="mini"
                >设备掉线</el-button
              >
              <el-button
                v-else-if="scope.row.warnType === 2"
                type="danger"
                size="mini"
                >累计预警</el-button
              >
              <el-button
                v-else-if="scope.row.warnType === 3"
                type="danger"
                size="mini"
                >相对预警</el-button
              >
            </template>
          </el-table-column>
          <!-- <el-table-column prop="dealType" label="处理方式">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.dealType === 0"
                type="success"
                size="mini"
                >正常</el-button
              >
              <el-button
                v-if="scope.row.dealType === 1"
                type="warning"
                size="mini"
                >设备掉线</el-button
              >
              <el-button
                v-if="scope.row.dealType === 2"
                type="danger"
                size="mini"
                >累计预警</el-button
              >
              <el-button
                v-if="scope.row.dealType === 3"
                type="danger"
                size="mini"
                >相对预警</el-button
              >
            </template>
          </el-table-column>
          <el-table-column prop="dealName" label="处理人"> </el-table-column>
          <el-table-column prop="dealTime" label="处理时间"> </el-table-column>
          <el-table-column prop="remark" label="处理备注"> </el-table-column> -->
          <el-table-column prop="warnLevel" label="预警等级">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.warnLevel == 0"
                type="success"
                size="mini"
                >正常</el-button
              >
              <el-button
                v-else-if="scope.row.warnLevel == 1"
                type="danger"
                size="mini"
                >红色预警</el-button
              >
              <el-button
                v-else-if="scope.row.warnLevel == 2"
                type="warning"
                size="mini"
                >橙色预警</el-button
              >
              <el-button
                v-else-if="scope.row.warnLevel == 3"
                size="mini"
                class="button-yellow"
                >黄色预警</el-button
              >
              <el-button
                v-else-if="scope.row.warnLevel == 4"
                type="primary"
                size="mini"
                >蓝色预警</el-button
              >
            </template>
          </el-table-column>
          <el-table-column prop="theDate" label="预警时间">
          </el-table-column>
        </el-table>
        <el-row type="flex" justify="end">
          <el-pagination
            @size-change="handleSizeChanges"
            @current-change="handleCurrentChanges"
            :current-page="querys.pages"
            :page-sizes="[10, 15]"
            :page-size="querys.pagesizes"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totals"
          >
          </el-pagination>
        </el-row>
      </el-tab-pane>
    </el-tabs>
  </el-card>
</template>

<script>
import { getMonitoringTypeAll } from "../../api/api";
import { getDataEarlyWarning } from "../../api/warning";
export default {
  name: "WarningReception",
  data() {
    return {
      options: [],
      tailingPondId: "",
      searchForm: {
        sensorList: null,
      },
      searchForms: {
        sensorLists: null,
      },
      activeName: "first",
      total: 0,
      query: {
        page: 1,
        pagesize: 10,
      },
      totals: 0,
      querys: {
        pages: 1,
        pagesizes: 10,
      },
      list: [],
      lists: [],
      warnType: 1,
      warnTypes: 2,
      rules: {
        sensorList: [
          { required: true, message: "请选择传感器类型", trigger: "change" },
        ],
      },
      ruless: {
        sensorList: [
          { required: true, message: "请选择传感器类型", trigger: "change" },
        ],
      },
      currentPage: 1,
    };
  },
  created() {
    this.tailingPondId = sessionStorage.getItem("sensorId");
    this.getlistss();
    this.getlist();
    this.getlists();
  },
  methods: {
    handleSizeChange(val) {
      this.query.pagesize = val;
      this.search();
    },
    handleCurrentChange(val) {
      this.query.page = val;
      this.search();
    },
    handleSizeChanges(val) {
      this.querys.pagesizes = val;
      this.searchs();
    },
    handleCurrentChanges(val) {
      this.querys.pages = val;
      this.searchs();
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    //所有类型
    async getlistss() {
      await getMonitoringTypeAll({ tailingPondId: this.tailingPondId }).then(
        (res) => {
          this.options = res.parameter;
        }
      );
    },
    //分页查询(数据)
    async getlist() {
      await getDataEarlyWarning({
        tailingPondId: this.tailingPondId,
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        warnType: this.warnTypes,
      }).then((res) => {
        if (res.resultCode == "200") {
          this.list = res.parameter.list;
          this.total = res.parameter.total;
        } else {
          this.list = [];
          this.total = 0;
        }
      });
    },
    //查询
    async search() {
      await getDataEarlyWarning({
        tailingPondId: this.tailingPondId,
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        monitorTypeId: this.searchForm.sensorList,
        warnType: this.warnTypes,
      }).then((res) => {
        if (res.resultCode == "200") {
          this.list = res.parameter.list;
          this.total = res.parameter.total;
        } else {
          this.list = [];
          this.total = 0;
        }
      });
    },
    //分页查询(设备)
    async getlists() {
      await getDataEarlyWarning({
        tailingPondId: this.tailingPondId,
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        warnType: this.warnType,
      }).then((res) => {
        if (res.resultCode == "200") {
          this.lists = res.parameter.list;
          this.totals = res.parameter.total;
        } else {
          this.lists = [];
          this.totals = 0;
        }
      });
    },

    //查询
    async searchs() {
      console.log(this.searchForm.sensorLists);
      await getDataEarlyWarning({
        tailingPondId: this.tailingPondId,
        pageCount: this.querys.pages,
        pageSize: this.querys.pagesizes,
        monitorTypeId: this.searchForms.sensorLists,
        warnType: this.warnType,
      }).then((res) => {
        console.log(res);
        if (res.resultCode == "200") {
          this.lists = res.parameter.list;
          this.totals = res.parameter.total;
        } else {
          this.lists = [];
          this.totals = 0;
        }
      });
    },
  },
};
</script>

<style scoped>
.content {
  /* margin-top: 0.2rem; */
  margin-left: 0.08rem;
  height: 90vh;
  /* background: pink; */
}
/* .content .el-button {
  width: 100px;
} */
.el-tabs {
  height: 86vh;
  /* background: pink; */
}
.top {
  margin-left: 0.2rem;
}
.el-tab-pane {
  height: 80vh;
  /* background: pink; */
  overflow: auto;
}
.button-yellow {
  background-color: #f0de1b;
  color: #fff;
}
.el-table {
  margin-bottom: 0.15rem;
  display: block;
  height: 63vh;
  overflow: auto;
  text-align: center;
}
.el-table::before {
  z-index: inherit;
}
</style>